package main

import (
	"github.com/gomodule/redigo/redis"
	"gitee.com/winnie_gss/microService/service-log"
	"os"
	"gopkg.in/ini.v1"
	"fmt"
)

var redisConfig RedisConfig
var conn redis.Conn
var pwd string

type RedisConfig struct {
	RdHost     string
	RdPort     string
	RdPassword string
}

func InitRedis() {
	pwd, _ = os.Getwd()
	pwd += "//static"
	file, err := ini.Load(pwd + "//config.ini")
	service_log.ErrorLog(err)

	file.BlockMode = false
	err = file.Section("redis").MapTo(&redisConfig)
	service_log.ErrorLog(err)

	conn, err = redis.Dial("tcp", redisConfig.RdHost+":"+redisConfig.RdPort, redis.DialPassword(redisConfig.RdPassword))
	service_log.ErrorLog(err)
}

func Set(key, val string) {
	v, err := conn.Do("SET", key, val)
	service_log.ErrorLog(err)
	fmt.Println(v)
}

func Get() {

}

//消息队列-Push(第一个参数是key)
func ListPush(args ...interface{}) (num int64) {
	v, err := conn.Do("RPUSH", args...)
	service_log.ErrorLog(err)
	num = v.(int64)
	return
}

//消息队列-Pop
func ListPop(key string) (v string) {
	v, err := redis.String(conn.Do("LPOP", key))
	service_log.ErrorLog(err)
	return
}

func main() {
	service_log.InitLog()
	InitRedis()

	n := ListPush("list1", 11, 22, 33, 44)
	fmt.Println(n)
}
